package org.ice4apps.talk.session.configuration;

import java.util.HashMap;
import java.util.List;

import javax.persistence.EntityManager;

import org.ice4apps.talk.entity.*;

public class PbxConfiguration {
	
//	@In EntityManager entityManager;

	public static List<PstnGatewayAccount> getPstnAccounts() {
		return PbxConfigurationHolder.pstnAccounts;
	}
	
	
	public static HashMap<String,GlobalProperty> getGlobalProperties() {
		return PbxConfigurationHolder.globalProperties;
	}
	
	public static String getProperty(String property) {
		return getGlobalProperties().get(property).getValue();
	}

	public void updateAll() throws InterruptedException {
		Thread.sleep(300);
//		log.info("Global settings updated");
		loadPstnAccounts();
		loadGlobalProperties();
	}
	
	public void loadGlobalProperties() {
        List<GlobalProperty> props = null;
//        entityManager.createQuery("SELECT global FROM GlobalProperty global").getResultList();
        HashMap<String,GlobalProperty> globalProperties = new HashMap<String, GlobalProperty>();
		for(GlobalProperty p : props) {
			globalProperties.put(p.getName(), p);
		}
		PbxConfigurationHolder.globalProperties = globalProperties;
	}
	
	public void loadPstnAccounts() {
		PbxConfigurationHolder.pstnAccounts = null;
//		entityManager.createQuery("SELECT pstn FROM PstnGatewayAccount pstn").getResultList();
	}
}
